package casts.misc
{
   import flash.display.MovieClip;
   import flash.events.Event;
   // greensock
   //import com.greensock.*;
   //import com.greensock.easing.*;

   /**
    * 簡單的顆粒動畫類別
    * @author     cjboy | cjboy1984@gmail.com
    * @usage
    * > 先將MovieClip的基底類別設成 casts.misc.BaseParticle
    * var cls:Class = getDefinitionByName('YourClass') as Class;
    * var part:MovieClip = new cls();
    * part.x = 100;
    * part.y = 100;
    * addChild(part);
    */
   public class BaseParticle extends MovieClip
   {

      /* constructor */
      public function BaseParticle()
      {
         mouseEnabled = false;
         mouseChildren = false;

         stop();

         addEventListener(Event.ADDED_TO_STAGE, onAdd);
         addEventListener(Event.REMOVED_FROM_STAGE, onRemove);
      }

      // ------------------ LINE -------------------

      // ################ Protected ################

      protected function onAdd(e:Event):void
      {
         gotoAndStop(1);
         MyTween.frameTo(this, totalFrames, { onComplete:removeSelf } );
      }

      protected function onRemove(e:Event):void
      {
         MyTween.kill(this);
      }

      // ################# Private #################

      private function removeSelf():void
      {
         parent.removeChild(this);
      }

      // ------------------ LINE -------------------

   }

}